home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / lib / AssocInt.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  2KB  |  100 lines

  1. /* AssocInt.c -- implementation of key-Integer association
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet: kgorlen@alw.nih.gov
  20.     September, 1985
  21.  
  22. Function:
  23.  
  24. Objects of class AssocInt associate a key object with an Integer value
  25. object.  They are used to implement Bags, which use a Dictionary to
  26. associate objects with their occurrence counts.
  27.  
  28. $Log:    AssocInt.c,v $
  29.  * Revision 3.0  90/05/20  00:19:04  kgorlen
  30.  * Release for 1st edition.
  31.  * 
  32. */
  33.  
  34. #include "AssocInt.h"
  35. #include "nihclIO.h"
  36.  
  37. #define    THIS    AssocInt
  38. #define    BASE    LookupKey
  39. #define BASE_CLASSES BASE::desc()
  40. #define MEMBER_CLASSES Integer::desc()
  41. #define VIRTUAL_BASE_CLASSES
  42.  
  43. DEFINE_CLASS(AssocInt,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/AssocInt.c,v 3.0 90/05/20 00:19:04 kgorlen Rel $",NULL,NULL);
  44.  
  45. AssocInt::AssocInt(Object& newKey, int newValue)
  46.     : BASE(newKey), avalue(newValue)
  47. {
  48. }
  49.  
  50. Object* AssocInt::value() { return &avalue; }
  51.  
  52. const Object* AssocInt::value() const { return &avalue; }
  53.  
  54. Object* AssocInt::value(Object& newValue)
  55. {
  56.     assertArgClass(newValue,*Integer::desc(),"value");
  57.     avalue = Integer::castdown(newValue);
  58.     return &avalue;
  59. }
  60.  
  61. void AssocInt::deepenShallowCopy()
  62. {
  63.     BASE::deepenShallowCopy();
  64.     avalue.deepenShallowCopy();
  65. }
  66.  
  67. static int intval;
  68.  
  69. AssocInt::AssocInt(OIOin& strm)
  70. :
  71. #ifdef MI
  72.     Object(strm),
  73. #endif
  74.     BASE(strm),
  75.     avalue((strm >> intval, intval))
  76. {
  77. }
  78.  
  79. void AssocInt::storer(OIOout& strm) const
  80. {
  81.     BASE::storer(strm);
  82.     strm << avalue.value();
  83. }
  84.  
  85. AssocInt::AssocInt(OIOifd& fd)
  86. :
  87. #ifdef MI
  88.     Object(fd),
  89. #endif
  90.     BASE(fd),
  91.     avalue((fd >> intval, intval))
  92. {
  93. }
  94.  
  95. void AssocInt::storer(OIOofd& fd) const
  96. {
  97.     BASE::storer(fd);
  98.     fd << avalue.value();
  99. }
  100.